package com.goods.shop.service.options;

import jdk.nashorn.internal.runtime.options.Option;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class TestOptional {
    class Student{
        private String name;
        private int age;
        private Integer score;

        public Student() {
        }

        public Student(String name, int age, Integer score) {
            this.name = name;
            this.age = age;
            this.score = score;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public Integer getScore() {
            return score;
        }

        public void setScore(Integer score) {
            this.score = score;
        }
    }
    public List<Student> initData(){
        Student s1=new Student("张三",19,80);
        Student s2=new Student("李四",18,85);
        Student s3=new Student("王五",20,80);
        Student s4=new Student("赵六",19,82);
        Student s5=new Student("钱七",16,86);
        Student s6=new Student("孙八",22,88);
        Student s7=new Student("吴九",21,90);
        return Arrays.asList(s1,s2,s3,s4,s5,s6,s7);
    }
    public static void main(String[] args) {
//        TestOptional service=new TestOptional();
//        List<Student> students=service.initData();
//        for (Student student : students) {
//            Optional<Student> studentOptional=Optional.of(student);
//            Integer score=studentOptional.filter(s->s.getAge()>=18).map(Student::getScore).orElse(0);
//            if(score>80){
//                System.out.println(student.getName());
//            }
//        }
//        String x="101";
//        Function<String,Integer> function=y->Integer.valueOf(y);
//        Integer result0=function.apply(x);
//        String val=null;
//        Optional<String> opational=Optional.ofNullable(val);
//        String result=Optional.ofNullable(val).map(m->new String(m+"append")).orElse("--");
//
////        String result=opational.map(function).map(v->new String(v+"append")).orElse("--");
//        System.out.println(result);
        List<String> results=Stream.of("a","b","book","collect","dark","eureka","fast","good","jeep","kind")
                .filter(e->e.length()>3).peek(e-> System.out.println("filteredvalue:"+e))
                .map(e->e.toUpperCase())
                .peek(e-> System.out.println("mapped value:"+e))
                .collect(Collectors.toList());
        System.out.println("================="+results.size()+"=====================");
        System.out.println("=======================result======================");
        for (String result : results) {
            System.out.println(result);
        }

    }
}
